package com.xxx.mch.controller;

import com.xxx.mch.service.impl.AuthorizationServiceImpl;
import com.xxx.mch.utils.WrapMapper;
import com.xxx.mch.utils.Wrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @date 2020/9/11
 */
@Slf4j
@RestController
@RequestMapping("auth")
@Api(tags = "权限管理")
public class AuthorizationController
{
    @Autowired
    private AuthorizationServiceImpl authorizationService;

    @ApiOperation(value = "根据传递的用户昵称，获取用户的权限")
    @GetMapping("/{loginName}")
    public Wrapper<List<String>> getPermissionCodeList(HttpServletRequest request, @PathVariable String loginName)
    {
        String token = request.getHeader("sobeyhive-http-token");
        return WrapMapper.ok(authorizationService.getPermissionCodeList(token, loginName));
    }
}
